package com.example.lenovo.demo.presenter;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.MainMapBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnMainMapSuccess;
import com.example.lenovo.demo.presenter.adapter.MainMapActicityRvAdapter;
import com.example.lenovo.demo.view.ifgview.IMainMapActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/13.
 */

public class MainMapPresenter implements IMainMapActivity {
    private Context context;
    private RecyclerView recyclerView;
    private String id;
    private ProgressDialog progressDialog;
    private IModel iModel;
    private MainMapActicityRvAdapter acticityRvAdapter;
    private List<Object> data;
    private LinearLayoutManager manager;

    public void initData(){
        progressDialog.show();
        data=new ArrayList<>();
        iModel=new Model();
        acticityRvAdapter=new MainMapActicityRvAdapter(data,context);
        manager=new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
        manager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(manager);
        iModel.sendMainMapBean(id, new OnMainMapSuccess() {
            @Override
            public void MainMapSuccess(MainMapBean mainMapBean) {
                List<MainMapBean.DataBean.DestinationsBean> destinationBeens=mainMapBean.getData().getDestinations();
                MainMapBean.DataBean.DestinationBean destinationBean=mainMapBean.getData().getDestination();
                destinationBean.setDestinations(destinationBeens);
                data.add(destinationBean);
                List<MainMapBean.DataBean.GroupingsBean> groupingsBeens=mainMapBean.getData().getGroupings();
                for (MainMapBean.DataBean.GroupingsBean groupingsBeen : groupingsBeens) {
                    data.add(groupingsBeen.getName());
                    data.addAll(groupingsBeen.getSections());
                }
                recyclerView.setAdapter(acticityRvAdapter);
                progressDialog.dismiss();
            }

            @Override
            public void MainMapFailed() {

            }
        });

    }

    @Override
    public void sendView(Context context, RecyclerView recyclerView, String id, ProgressDialog progressDialog) {
        this.context=context;
        this.id=id;
        this.recyclerView=recyclerView;
        this.progressDialog=progressDialog;

    }
}
